package com.cskaoyan.service;

import com.cskaoyan.bean.vo.zxw.*;

import com.cskaoyan.mapper.marketMapper.MarketGoodsMapper;
import com.cskaoyan.mapper.marketMapper.MarketOrderMapper;
import com.cskaoyan.mapper.marketMapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曾添乐啦
 * @since 2022/12/30 09:03
 */
@Service
public class AdminStatServiceImpl implements AdminStatService {

    @Autowired
    MarketUserMapper marketUserMapper;

    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Autowired
    MarketGoodsMapper marketGoodsMapper;

    /**
     * 从用户表中根据时间来分组查询
     * {day: "2022-11-22", users: 3}
     *
     * @return
     */
    //查询用户统计配置
    @Override
    public StatUserVo findUserStat() {

        //查询
        List<StatUserRowsVo> statUserRowsVos = marketUserMapper.selectUserStatGroupByAddTime();
        //TODO:这里有bug,不知道为什么给我报空指针异常，我每次debug到这个位置，它就调到其他servlet里面
        List<String> columns = new ArrayList<>();
        //TODO:数组添加顺序会影响页面回显
        columns.add("day");
        columns.add("users");

        //拼接查询条件

        //封装返回结果
        StatUserVo statUserVo = new StatUserVo();
        statUserVo.setColumns(columns);
        statUserVo.setRows(statUserRowsVos);
        return statUserVo;
    }

    /**
     * {amount: 817, orders: 4, customers: 1, day: "2022-07-15", pcr: 817}
     *
     * @return
     */
    //查询订单统计配置
    @Override
    public StatOrderVo findOrderStat() {
        //查询
        List<StatOrderRowsVo> statOrderRowsVos = marketOrderMapper.selectOrderStatGroupByAddTime();

        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");

        //拼接查询条件

        //封装返回结果
        StatOrderVo statOrderVo = new StatOrderVo();
        statOrderVo.setColumns(columns);
        statOrderVo.setRows(statOrderRowsVos);
        return statOrderVo;
    }

    /**
     * {amount: 2989, orders: 10, day: "2022-07-15", products: 11}
     *
     * @return
     */
    //查询商品统计配置
    @Override
    public StatGoodsVo findGoodsStat() {
        //查询
        List<StatGoodsRowsVo> statGoodsRowsVos = marketGoodsMapper.selectGoodsStatGroupByAddTime();
        //拼接查询条件
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");

        //封装返回结果
        StatGoodsVo statGoodsVo = new StatGoodsVo();
        statGoodsVo.setColumns(columns);
        statGoodsVo.setRows(statGoodsRowsVos);
        return statGoodsVo;
    }
}
